package fxc.example;

import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.commons.math3.distribution.PoissonDistribution;

import java.util.ArrayList;
import java.util.List;

public class Model {
    List<Variable> variables;
    List<Double> betas;

    public Model(){
        variables = new ArrayList<>();
        betas = new ArrayList<>();
    }
    public void addNormalVariable(double mean, double sd, double beta){
        NormalDistributionVariable var = new NormalDistributionVariable(mean, sd);
        variables.add(var);
        betas.add(beta);
    }
    public void addPoissonVariable(double mean, double beta){
        PoissonDistributionVariable var = new PoissonDistributionVariable(mean);
        variables.add(var);
        betas.add(beta);
    }
    double residual;
    double getDependent(double[] sampleVector){
        double result = 0.0d;
        if (sampleVector.length!=variables.size()){
            throw new RuntimeException("sampleVector.length!=variables.size");
        }
        for (int i=0;i<variables.size();i++){
            result+=betas.get(i)*sampleVector[i];
        }
        result += residual;
        return result;
    }



    double getBaseCase(){

        double baseCase = 0.0d;
        for (int i=0;i<variables.size();i++){
            if (variables.get(i).getDistributionType().equals("normalDistribution")) {
                NormalDistributionVariable variable = (NormalDistributionVariable) variables.get(i);
                NormalDistribution normalDistribution = (NormalDistribution) variable.getDistribution();
                baseCase += betas.get(i) * normalDistribution.getMean();
            }else if (variables.get(i).getDistributionType().equals("poissonDistribution")) {
                PoissonDistributionVariable variable = (PoissonDistributionVariable) variables.get(i);
                PoissonDistribution poissonDistribution = (PoissonDistribution) variable.getDistribution();
                baseCase += betas.get(i) * poissonDistribution.getMean();
            }

        }
        baseCase += residual;
        return baseCase;

    }
}
